package xsis.music.dao.impl;

import java.io.IOException;

import org.hibernate.Query;
import org.hibernate.SQLQuery;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import org.springframework.stereotype.Service;

import xsis.music.dao.UserDao;
import xsis.music.model.UserModel;
@Service
public class UserDaoImpl extends HibernateDaoSupport implements UserDao{
	@Autowired
	public UserDaoImpl(SessionFactory sessionFactory) {
		setSessionFactory(sessionFactory);
	}
	@Override
	public void updateAktifasi(UserModel user) throws IOException {
		// TODO Auto-generated method stub
		 SQLQuery query = getSession().createSQLQuery("update User set enabled=?  where email = ? and password= ? and kode= ?");
		 query.setParameter(0, 1);	
		 query.setParameter(1, user.getEmail());
		 query.setParameter(2, user.getPassword());
		 query.setParameter(3, user.getKode());
		int result= query.executeUpdate();
		System.out.println(user.getEmail()+user.getPassword()+user.getKode());
	}
	@Override
	public void insert(UserModel user) throws IOException {
		// TODO Auto-generated method stub
		 getHibernateTemplate().save(user);
		
	}
	
}
